package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/TestServlet4")
public class TestServlet4 extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter pw = resp.getWriter();
		
		Cookie c = new Cookie("nickname","小明");
		resp.addCookie(c);
		
		
		

		int[] arr = {1,2,3,4,5};
		req.setAttribute("arr", arr);
		
		
		List<String> list = new ArrayList<String>();
		list.add("张三");
		list.add("李四");
		list.add("张三");
		req.setAttribute("list", list);
		
		User u = new User();
		u.setName("刘备");
		u.setAge(18);
		req.setAttribute("user", u);
		
		req.getRequestDispatcher("/WEB-INF/4其他信息.jsp").forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}